package com.mock.action.geography.trustdistrict;

import java.util.ArrayList;
import java.util.List;

import com.mock.action.AbstractAction;
import com.mock.dao.TrustDistrictDao;
import com.mock.dao.impl.TrustDistrictDaoImp;
import com.mock.model.DataTable;
import com.mock.model.TrustDistrict;

public class TrustDistrictAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String setActive() {				
		TrustDistrict trustDistrict = trustDistrictDao.getById(trustDistrictId);
		trustDistrict.setActive(true);
		trustDistrictDao.update(trustDistrict);
		return SUCCESS;
	}
	
	public String trustDistrictTableAjax() throws Exception {
		DataTable dt = new DataTable();
		dt.sEcho = sEcho = getRequest().getParameter("sEcho");
		dt.iDisplayStart = iDisplayStart = Integer.parseInt(getRequest()
				.getParameter("iDisplayStart"));
		dt.iDisplayLength = iDisplayLength = Integer.parseInt(getRequest()
				.getParameter("iDisplayLength"));
		dt.sSearch_0 = sSearch_0 = getRequest().getParameter("sSearch_0");		
		dt.sSearch_3 = sSearch_3 = getRequest().getParameter("sSearch_3");		
		dt.iSortCol_0 = iSortCol_0 = Integer.parseInt(getRequest()
				.getParameter("iSortCol_0"));
		dt.sSortDir_0 = sSortDir_0 = getRequest().getParameter("sSortDir_0");
		iTotalDisplayRecords = trustDistrictDao.getTotalRecordByQuery(dt, trustRegionId);
		iTotalRecords = trustDistrictDao.getRowCount();
		List<TrustDistrict> trustDistricts = trustDistrictDao.getTrustDistrictByQuery(dt, trustRegionId);
		for (TrustDistrict trustDistrict : trustDistricts) {
			ArrayList<String> newArray = new ArrayList<String>();
			newArray.add(trustDistrict.getName());
			newArray.add(trustDistrict.getDescription());
			newArray.add(trustDistrict.getTrustRegion().getName());
			if (trustDistrict.isActive()) {
				newArray.add("Yes");				
			} else {				
				newArray.add("No");				
			}
			newArray.add(Long.toString(trustDistrict.getTrustDistrictId()));
			newArray.add(Long.toString(trustDistrict.getTrustRegion().getTrustRegionId()));
			aaData.add(newArray);
		}
		return SUCCESS;
	}
	
	private TrustDistrictDao trustDistrictDao = new TrustDistrictDaoImp();
	private List<ArrayList<String>> aaData = new ArrayList<ArrayList<String>>();
	private long trustRegionId = -1L;
	private long trustDistrictId = -1L;
	private String sEcho;
	private String sSearch;
	private int iDisplayLength;
	private int iDisplayStart;
	private int iTotalRecords;
	private Long iTotalDisplayRecords;
	private String sSearch_0;
	private int iSortCol_0;
	private String sSortDir_0;
	private String sSearch_3;

	public List<ArrayList<String>> getAaData() {
		return aaData;
	}

	public void setAaData(List<ArrayList<String>> aaData) {
		this.aaData = aaData;
	}

	public long getTrustRegionId() {
		return trustRegionId;
	}

	public void setTrustRegionId(long trustRegionId) {
		this.trustRegionId = trustRegionId;
	}

	public long getTrustDistrictId() {
		return trustDistrictId;
	}

	public void setTrustDistrictId(long trustDistrictId) {
		this.trustDistrictId = trustDistrictId;
	}

	public String getsEcho() {
		return sEcho;
	}

	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}

	public String getsSearch() {
		return sSearch;
	}

	public void setsSearch(String sSearch) {
		this.sSearch = sSearch;
	}

	public int getiDisplayLength() {
		return iDisplayLength;
	}

	public void setiDisplayLength(int iDisplayLength) {
		this.iDisplayLength = iDisplayLength;
	}

	public int getiDisplayStart() {
		return iDisplayStart;
	}

	public void setiDisplayStart(int iDisplayStart) {
		this.iDisplayStart = iDisplayStart;
	}

	public int getiTotalRecords() {
		return iTotalRecords;
	}

	public void setiTotalRecords(int iTotalRecords) {
		this.iTotalRecords = iTotalRecords;
	}

	public Long getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}

	public void setiTotalDisplayRecords(Long iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}

	public String getsSearch_0() {
		return sSearch_0;
	}

	public void setsSearch_0(String sSearch_0) {
		this.sSearch_0 = sSearch_0;
	}

	public int getiSortCol_0() {
		return iSortCol_0;
	}

	public void setiSortCol_0(int iSortCol_0) {
		this.iSortCol_0 = iSortCol_0;
	}

	public String getsSortDir_0() {
		return sSortDir_0;
	}

	public void setsSortDir_0(String sSortDir_0) {
		this.sSortDir_0 = sSortDir_0;
	}

	public String getsSearch_3() {
		return sSearch_3;
	}

	public void setsSearch_3(String sSearch_3) {
		this.sSearch_3 = sSearch_3;
	}
	
}
